package com.zjzywl.smoke.controller;
import javax.websocket.server.PathParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.zjzywl.smoke.config.AppConfig;
import com.zjzywl.smoke.controller.BaseController;
import com.zjzywl.smoke.util.WebResult;

@RestController
@RequestMapping(value = "/paging")
public class PagingController extends BaseController {
	@Autowired
	private AppConfig appConfig;

	// 统计异常设备上报信息数量总页数
	@RequestMapping(value = "/count/pageNumber", method = RequestMethod.GET)
	public WebResult getCountByStatusAndDeviceTypeAndUser(@PathParam("status") String status,
			@PathParam("deviceTypeId") String deviceTypeId, @PathParam("startTime") String startTime,
			@PathParam("endTime") String endTime, @PathParam("disposePeople") String disposePeople,
			@PathParam("devCode") String devCode) {
		String userId = this.getUserId();
		ResponseEntity<Object> devices = appConfig.restTemplate().exchange(
				appConfig.getGetDataIp() + "/paging/count/pageNumber/" + status + "/" + deviceTypeId + "/" + userId
						+ "/" + startTime + "/" + endTime + "/" + disposePeople + "/" + devCode,
				HttpMethod.GET, null, Object.class);
		return WebResult.OK(devices);
	}

	// 统计异常设备上报信息当前页信息
	@RequestMapping(value = "/count/approve", method = RequestMethod.GET)
	public WebResult getCountByStatusApprove(@PathParam("status") String status,
			@PathParam("deviceTypeId") String deviceTypeId, @PathParam("page") int page,
			@PathParam("startTime") String startTime, @PathParam("endTime") String endTime,
			@PathParam("disposePeople") String disposePeople, @PathParam("devCode") String devCode) {
		String userId = this.getUserId();
		ResponseEntity<Object> devices = appConfig.restTemplate().exchange(
				appConfig.getGetDataIp() + "/paging/count/approve/" + status + "/" + deviceTypeId + "/" + userId + "/"
						+ page + "/" + startTime + "/" + endTime + "/" + disposePeople + "/" + devCode,
				HttpMethod.GET, null, Object.class);
		return WebResult.OK(devices);
	}

	// 统计历史上报信息数量总页数
	@GetMapping(value = "/data/history/pageNumber")
	public WebResult getAlarmSimplePageNumber(@PathParam("beginTime") String beginTime,
			@PathParam("endTime") String endTime, @PathParam("alarmTypeCode") String alarmTypeCode,
			@PathParam("deviceTypeId") String deviceTypeId, @PathParam("address") String address,
			@PathParam("alarmReasons") String alarmReasons,@PathParam("devCode") String devCode) {
		String userId = this.getUserId();
		ResponseEntity<Object> alarms = appConfig.restTemplate()
				.exchange(appConfig.getGetDataIp() + "/paging/data/history/pageNumber/" + beginTime + "/" + endTime
						+ "/" + alarmTypeCode + "/" + deviceTypeId + "/" + address + "/" + userId + "/" + alarmReasons+"/"+ devCode,
						HttpMethod.GET, null, Object.class);
		return WebResult.OK(alarms);
	}

	// 统计历史设备上报信息数量当前页
	@GetMapping(value = "/data/history/Approve")
	public WebResult getAlarmSimpleApprove(@PathParam("beginTime") String beginTime,
			@PathParam("endTime") String endTime, @PathParam("alarmTypeCode") String alarmTypeCode,
			@PathParam("deviceTypeId") String deviceTypeId, @PathParam("address") String address,
			@PathParam("page") int page, @PathParam("alarmReasons") String alarmReasons,@PathParam("devCode") String devCode) {
		String userId = this.getUserId();
		ResponseEntity<Object> alarms = appConfig.restTemplate()
				.exchange(appConfig.getGetDataIp() + "/paging/data/history/Approve/" + beginTime + "/" + endTime + "/"
						+ alarmTypeCode + "/" + deviceTypeId + "/" + address + "/" + userId + "/" + page + "/"
						+ alarmReasons+"/"+devCode, HttpMethod.GET, null, Object.class);
		return WebResult.OK(alarms);
	}

	// 根据设备名称模糊查询设备获取总页数
	@RequestMapping(value = "/data/list/bypageNumber")
	@ResponseBody
	public WebResult getByUserAndDeviceTypeAndpageNumber(@PathParam("deviceTypeId") String deviceTypeId,
			@PathParam("alarmCode") String alarmCode, @PathParam("address") String address) {
		String userId = getUserId();
		ResponseEntity<Object> alarms = appConfig.restTemplate()
				.exchange(appConfig.getGetDataIp() + "/paging/data/list/bypageNumber" + "/" + userId + "/"
						+ deviceTypeId + "/" + alarmCode + "/" + address, HttpMethod.GET, null, Object.class);

		return WebResult.OK(alarms);

	}

	// 根据设备名称模糊查询设备获取当前页
	@RequestMapping(value = "/data/list/bydeviceTypeApprove")
	@ResponseBody
	public WebResult getByUserAndDeviceTypeApprove(@PathParam("userId") String userId,
			@PathParam("deviceTypeId") String deviceTypeId, @PathParam("alarmCode") String alarmCode,
			@PathParam("address") String address, @PathParam("page") int page) {
		// String userId = getUserId();
		ResponseEntity<Object> alarms = appConfig.restTemplate()
				.exchange(
						appConfig.getGetDataIp() + "/paging/data/list/bydeviceTypeApprove/" + userId + "/"
								+ deviceTypeId + "/" + alarmCode + "/" + address + "/" + page,
						HttpMethod.GET, null, Object.class);

		return WebResult.OK(alarms);
	}

	// 未处理总页数
	@RequestMapping(value = "/notdispose/smoke/pageNumber")
	public WebResult getNotDisposeSmokeAlarmByUser() {
		String userId = this.getUserId();
		ResponseEntity<Object> alarms = appConfig.restTemplate().exchange(
				appConfig.getGetDataIp() + "/paging/notDeal/pageNumber/" + userId, HttpMethod.GET, null, Object.class);
		return WebResult.OK(alarms);
	}

	// 未处理当前页
	@RequestMapping(value = "/notdispose/smoke/approve/{page}")
	public WebResult notDeal(@PathVariable("page") int page) {
		String userId = this.getUserId();
		ResponseEntity<Object> alarms = appConfig.restTemplate().exchange(
				appConfig.getGetDataIp() + "/paging/notDeal/approve/" + userId + "/" + page, HttpMethod.GET, null,
				Object.class);
		return WebResult.OK(alarms);
	}

	// 设备管理：按照设备类型、用户、设备状态。获取所有设备信息总页数
	@RequestMapping(value = "/data/list/bydevicetype/pageNumber")
	public WebResult getDSByDeviceTypePageNumber(@PathParam("deviceTypeId") String deviceTypeId,
			@PathParam("status") String status, @PathParam("devCode") String devCode, @PathParam("address") String address) {
		String userId = this.getUserId();
		ResponseEntity<Object> deviceTypes = appConfig.restTemplate().exchange(appConfig.getGetDataIp()
				+ "/paging/data/list/byPageNumber/" + "/" + deviceTypeId + "/" + userId + "/" + status + "/" + devCode+"/"+address,
				HttpMethod.GET, null, Object.class);
		return WebResult.OK(deviceTypes);
	}

	// 设备管理：按照设备类型、用户、设备状态。获取所有设备信息当前页
	@RequestMapping(value = "/data/list/bydevicetype/approve")
	public WebResult getDSByDeviceTypeApprove(@PathParam("deviceTypeId") String deviceTypeId,
			@PathParam("status") String status, @PathParam("devCode") String devCode, @PathParam("page") String page, @PathParam("address") String address) {
		String userId = this.getUserId();
		ResponseEntity<Object> deviceTypes = appConfig.restTemplate()
				.exchange(appConfig.getGetDataIp() + "/paging/data/list/byApprove/" + "/" + deviceTypeId + "/" + userId
						+ "/" + status + "/" + devCode + "/" + page+ "/" + address, HttpMethod.GET, null, Object.class);
		return WebResult.OK(deviceTypes);
	}

	// 获取账号列表总页数，根据path
	@RequestMapping(value = "/pageNumber/user")
	public WebResult getCurrentUserPageNumber() {
		String userId = this.getUserId();
		ResponseEntity<Object> users = appConfig.restTemplate().exchange(
				appConfig.getGetDataIp() + "/paging/pageNumber/user/" + userId, HttpMethod.GET, null, Object.class);
		return WebResult.OK(users);
	}

	// 获取账号列表当前页，根据path
	@RequestMapping(value = "/approve/user/{page}")
	public WebResult getCurrentUserPageNumber(@PathVariable("page") Integer page) {
		String userId = this.getUserId();
		ResponseEntity<Object> users = appConfig.restTemplate().exchange(
				appConfig.getGetDataIp() + "/paging/approve/user/" + userId + "/" + page, HttpMethod.GET, null,
				Object.class);
		return WebResult.OK(users);
	}

	// 获取组织列表总页数
	@RequestMapping(value = "/organization/pageNumber")
	public WebResult getOrganizationData(@PathParam("type") String type) {
		String loginName = this.getLoginUser().getPeople().getLoginName();
		ResponseEntity<Object> orgs = appConfig.restTemplate().getForEntity(
				appConfig.getGetDataIp() + "/paging/organization/pageNumber?loginName=" + loginName + "&type=" + type,
				Object.class);
		return WebResult.OK(orgs);
	}

	// 获取组织列表当前页
	@RequestMapping(value = "/organization/approve")
	public WebResult getOrganizationDataApprove(@PathParam("type") String type, @PathParam("page") int page) {
		String loginName = this.getLoginUser().getPeople().getLoginName();
		ResponseEntity<Object> orgs = appConfig.restTemplate().getForEntity(appConfig.getGetDataIp()
				+ "/paging/organization/approve?loginName=" + loginName + "&type=" + type + "&page=" + page,
				Object.class);
		return WebResult.OK(orgs);
	}

	// 获取消防站列表当前页
	@RequestMapping(value = "/organizationfire/approve")
	public WebResult getOrganizationData(@PathParam("type") String type, @PathParam("page") int page) {
		String loginName = this.getLoginUser().getPeople().getLoginName();
		ResponseEntity<Object> orgs = appConfig.restTemplate().getForEntity(appConfig.getGetDataIp()
				+ "/paging/organizationfire/approve?loginName=" + loginName + "&type=" + type + "&page=" + page,
				Object.class);
		return WebResult.OK(orgs);
	}

	// 获取消防站列表总页数
	@RequestMapping(value = "/organizationfire/pageNumber")
	public WebResult getOrganizationDataPageNumber(@PathParam("type") String type) {
		String loginName = this.getLoginUser().getPeople().getLoginName();
		ResponseEntity<Object> orgs = appConfig.restTemplate().getForEntity(appConfig.getGetDataIp()
				+ "/paging/organizationfire/pageNumber?loginName=" + loginName + "&type=" + type, Object.class);
		return WebResult.OK(orgs);
	}
}
